--------------------------------------------------------------------------------------------------------------------------------wuee
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------

--[[ items are collected in the table item
     helmets: 1001.1 - 2000.1
     armor: 2001.1 - 3000.1
     boots: 3001.1 - 4000.1
     wapons: 4001.1 -5000.1
     if the item is different to the basic item you 
     ]]
     
-- 
 function Character:getItem(_item) -- the hero get an item. this function ( and the needed slot system) shoul be integrated into the class character=> npc and monsters can have items
local _break

for _i = 1,5 do 
  for _ii = 1,24 do 
    if  self.inventory[_i][_ii].item == nil then   self.inventory[_i][_ii].item = _item  _break = 1 break end

    if _i == 5 and _ii ==24 then print('no space left') end
  end
  if _break then break end
end
end

function Character:replaceItem(oldSlot,newSlot)
	
	if  newSlot.item then
		
	else
		newSlot.item = oldSlot.item
		oldSlot.item = nil
	end

end

function  Character:equipItem(inventorySlot, equipmentSlot)
	for k,v in pairs (item.requirement) do
 		if inventorySlot.item.requirement[k] <= self[k] then
			if equipmentSlot.item == nil then
		    	if equipmentSlot.typus == inventorySlot.item.typus then
		 		 	self:replaceItem(inventorySlot, equipmentSlot)
				else 
					print ('You can\'t set this item there ')
				end
		  	else 
				print('There is already an item.')
		  	end
		else
			print("you cant use this item")
		end
	end
end

function Character:checkEquipment()
	
end


----------------------------------------------------------------------
----------INVENTORY--------------------------------------------------
----------------------------------------------------------------------

function Character:newInventorySlot(pLayer,pRow,pColumn,pPosition) -- this function is used to create the slots for the following iteration. 
                        o = {
                        layer = pLayer,
                        row = pRow,
						column = pColumn,
						position = pPosition,
                        item = nil,
                        amount = 0,
                        --[[position_x = (_ii-1) * 10, -- hard coded, in the end should this be dynamic
                        position_y = (_iii-1) * 10,
                        length_x = 9,
                        length_y = 9 ]]--
                              }
                        return o
                        
end

function Character:createInventory(colums, rows, layers)
self.inventory = {}               		
for i= 1,layers do 
  self.inventory[i] = {}
  for ii=1,colums do 
    for iii= 1,rows do 
      if c then c = c +1 else c = 1 end
      self.inventory[i][c] = self:newInventorySlot(i,ii,iii,c)

    end
  end
c = nil
end

end

----------------------------------------------------------------------
----------EQUIPMENT--------------------------------------------------
----------------------------------------------------------------------

--possible equipment slots

function Character:newEquipmentSlot(pTypus) -- this function is used to create the slots for the following iteration. 
	o = {
			item = nil,
			typus = pTypus,
		}            
return o
                        
end

function Character:createEquipment()

	self.equipment = {}
	for k, v in pairs(self.equipmentSlots)  do  
  	self.equipment[k] = self:newEquipmentSlot(v)
                        
	end
end

function Character:readEquipment()
  local o = {} 
                
  for k, v in pairs(self.equipment) do 
    
    if self.equipment[k].item then 
     	for kk,vv in pairs(self.equipment[k].item.bonus) do
			if  o[kk] then 
      			o[kk] = o[kk] + self.equipment[k].item.bonus[kk]
     		else
				o[kk]= self.equipment[k].item.bonus[kk]
			end
		end
    end
  end
  
  return o
end
